package com.ipt.frm.pw.listener;

import java.io.IOException;
import java.util.Properties;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * Application Lifecycle Listener implementation class ContextListener
 * 
 */
public class ContextListener implements ServletContextListener {

	static Properties propertiesMsg;
	static private final String PATH_PROPERTIES_MSG = "/WEB-INF/config/messages.properties";

	/**
	 * Metodo que se lanzara al inicializar nuestra aplicaicon
	 * 
	 * @see ServletContextListener#contextInitialized(ServletContextEvent)
	 */
	@Override
	public void contextInitialized(ServletContextEvent sce) {

		// TODO comentar la jugada en logj4
		propertiesMsg = new Properties();
		try {

			propertiesMsg.load(sce.getServletContext().getResourceAsStream(
					PATH_PROPERTIES_MSG));

			sce.getServletContext()
					.setAttribute("propertiesMsg", propertiesMsg);
		} catch (IOException e) {

			e.printStackTrace();
		}
	}

	/**
	 * @see ServletContextListener#contextDestroyed(ServletContextEvent)
	 */
	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		sce.getServletContext().removeAttribute("propertiesMsg");
		propertiesMsg = null;
	}

}
